/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Views.GestionRestaurant;


import Model.Restaurant;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author ibrahim
 */
public class RestaurantTableModel extends AbstractTableModel {
    
    private List<Restaurant>db;
    private String[] colNames = {"ID","Name","StreetNumber","City","PostalCode","Restaurateur"};
    public  RestaurantTableModel (){};
        
    
    public void setData(List<Restaurant>db){
       this.db=db;
    }
    @Override
    public int getRowCount() {
        return db.size();
    }
   
    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public String getColumnName(int column) {
        return colNames[column]; //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
       switch(columnIndex){
            case 0:
                return Integer.class;
            case 1:
                return String.class;
            case 2:
                return Integer.class;
            case 3:
                return String.class;
            case 4:
                return String.class;
            case 5:
                return String.class;
           
            default:
                return null;
        } 
    }
    

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 1:
                return true;
            case 2:
                return true;
            case 3:
                return true;
            case 4:
                return true;
            case 5:
                return true;
            
            default:
                return false;
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        if (db==null) return;
        Restaurant restaurant = db.get(rowIndex);
         switch(columnIndex){
            case 1:
                  restaurant.setName((String)aValue);
                break;
            case 2:
                  restaurant.setNumStreet((Integer)aValue);
                break;
            case 3:
                  restaurant.setCity((String)aValue);
                break;
            case 4:
                  restaurant.setPostalCode((String)aValue);
                break;
            case 5:
                  restaurant.setRestaurateur((String)aValue);
                
            default:
                return;
         }
    }
    

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Restaurant restaurant = db.get(rowIndex);
        switch(columnIndex){
            case 0:
                return restaurant.getId();
            case 1:
                return restaurant.getName();
            case 2:
                return restaurant.getNumStreet();
            case 3:
                return restaurant.getCity();
            case 4:
                return restaurant.getPostalCode();
            case 5:
                return restaurant.getRestaurateur();
            
        }
    return null;
}
    
}
